﻿using System;
using System.Windows;
using System.Windows.Controls;

namespace Hetymine.Executioner.Controls {
    public class AlignmentComboBox : ComboBox {
        public AlignmentComboBox() {
            ComboBoxItem item = new ComboBoxItem();
            item.Content = "Left Top";
            this.Items.Add(item);

            item = new ComboBoxItem();
            item.Content = "Centre Top";
            this.Items.Add(item);

            item = new ComboBoxItem();
            item.Content = "Right Top";
            this.Items.Add(item);

            item = new ComboBoxItem();
            item.Content = "Left Centre";
            this.Items.Add(item);

            item = new ComboBoxItem();
            item.Content = "Centre Centre";
            this.Items.Add(item);

            item = new ComboBoxItem();
            item.Content = "Right Centre";
            this.Items.Add(item);

            item = new ComboBoxItem();
            item.Content = "Left Bottom";
            this.Items.Add(item);

            item = new ComboBoxItem();
            item.Content = "Centre Bottom";
            this.Items.Add(item);

            item = new ComboBoxItem();
            item.Content = "Right Bottom";
            this.Items.Add(item);
        }

        public string Alignment {
            get {
                switch (this.SelectedIndex) {
                    case 0:
                        return "left top";
                    case 1:
                        return "centre top";
                    case 2:
                        return "right top";
                    case 3:
                        return "left centre";
                    case 5:
                        return "right centre";
                    case 6:
                        return "left bottom";
                    case 7:
                        return "centre bottom";
                    case 8:
                        return "right bottom";
                    default:
                        return "centre centre";
                }
            }
            set {
                switch (value.ToLower()) {
                    case "left top":
                    case "top left":
                        this.SelectedIndex = 0;
                        break;
                    case "centre top":
                    case "center top":
                    case "top centre":
                    case "top center":
                        this.SelectedIndex = 1;
                        break;
                    case "right top":
                    case "top right":
                        this.SelectedIndex = 2;
                        break;
                    case "left centre":
                    case "left center":
                    case "centre left":
                    case "center left":
                        this.SelectedIndex = 3;
                        break;
                    case "right centre":
                    case "right center":
                    case "centre right":
                    case "center right":
                        this.SelectedIndex = 5;
                        break;
                    case "left bottom":
                    case "bottom left":
                        this.SelectedIndex = 6;
                        break;
                    case "centre bottom":
                    case "center bottom":
                    case "bottom centre":
                    case "bottom center":
                        this.SelectedIndex = 7;
                        break;
                    case "right bottom":
                    case "bottom right":
                        this.SelectedIndex = 8;
                        break;
                    default:
                        this.SelectedIndex = 4;
                        break;
                }
            }
        }
    }
}
